unit uPadrao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, StdCtrls, Buttons, Grids, DBGrids, DB;

type
  TfrmPadrao = class(TForm)
    PageControl1: TPageControl;
    tabPesquisa: TTabSheet;
    TabCadastro: TTabSheet;
    Panel1: TPanel;
    btnIncluir: TSpeedButton;
    btnAlterar: TSpeedButton;
    btnExcluir: TSpeedButton;
    btnVoltar: TSpeedButton;
    edtPesquisa: TEdit;
    btnPesquisa: TSpeedButton;
    Panel2: TPanel;
    DBGrid1: TDBGrid;
    btnSalvar: TSpeedButton;
    btnCancelar: TSpeedButton;
    btnVoltaCadastro: TSpeedButton;
    DsManutencao: TDataSource;
    sbCadastro: TStatusBar;
    painel: TPanel;
    procedure DsManutencaoDataChange(Sender: TObject; Field: TField);
    procedure btnIncluirClick(Sender: TObject);
    procedure btnCancelarClick(Sender: TObject);
    procedure btnVoltarClick(Sender: TObject);
    procedure btnVoltaCadastroClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DsManutencaoStateChange(Sender: TObject);
  
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmPadrao: TfrmPadrao;

implementation

{$R *.dfm}

procedure TfrmPadrao.DsManutencaoDataChange(Sender: TObject;
  Field: TField);
begin
if DsManutencao.DataSet.RecordCount = 0 then
  begin
    btnAlterar.Enabled := False;
    btnExcluir.Enabled := False;
  end
  else
  begin
    btnAlterar.Enabled := True;
    btnExcluir.Enabled := True;
  end;
end;

procedure TfrmPadrao.btnIncluirClick(Sender: TObject);
begin
  tabCadastro.show;
end;

procedure TfrmPadrao.btnCancelarClick(Sender: TObject);
begin
  tabPesquisa.Show;
end;

procedure TfrmPadrao.btnVoltarClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmPadrao.btnVoltaCadastroClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmPadrao.FormShow(Sender: TObject);
begin
  tabPesquisa.Show;
end;

procedure TfrmPadrao.DsManutencaoStateChange(Sender: TObject);
begin
if (dsManutencao.State in [dsInsert,dsEdit]) then // se estiver incluindo ou alterando
  begin
    tabPesquisa.TabVisible   := False;
    tabCadastro.TabVisible   := True;
    btnVoltaCadastro.Enabled := False;
    btnSalvar.Enabled        := True;
    btnCancelar.Enabled      := True;

    if (dsManutencao.State = dsInsert) then
      sbCadastro.Panels[1].Text := ' Incluindo'
    else if (dsManutencao.State = dsEdit) then
      sbCadastro.Panels[1].Text := ' Alterando';
  end
  else
  begin
    tabPesquisa.TabVisible   := True;
    tabCadastro.TabVisible   := True;
    btnVoltaCadastro.Enabled := True;
    btnSalvar.Enabled        := False;
    btnCancelar.Enabled      := False;

    sbCadastro.Panels[0].Text:= '';
  end;
end;



end.
